package org.hdax.controller;

import org.hdax.entity.Role;
import org.hdax.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping(value = "/role")
@Controller
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/index")
    public String index(){
        return "role/list";
    }

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> list(@RequestParam("offset")int offset,@RequestParam("limit")int limit,Role condition){
        Map<String,Object> map = new HashMap<String, Object>();
        List<Role> roles = roleService.getByPage(offset, limit, condition);
        int count = roleService.getCount(condition);
        map.put("rows",roles);
        map.put("total",count);
        return map;
    }
}
